home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Storage / TransDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  23.6 KB  |  818 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TransDlg.cpp
  3.  
  4.     Contains:    C++ Implementation for Translation Dialog class.
  5.  
  6.     Owned by:    Craig Carper
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>      6/5/96    EL        1355529: Use menu item count to determine
  13.                                     the translation menu item.
  14.          <2>      6/4/96    EL        1279544: Move GetTypeListItem from
  15.                                     TransDlg.cpp to InfoUtil.cpp.
  16.         <30>    10/16/95    CC        GM 1291441: InitialEditorSetup: Translation
  17.                                     disabled if only one translate-kind
  18.                                     possible.
  19.                                     GM 1292157: Removed static function
  20.                                     GetEditorFromList; call
  21.                                     GetThisEditorFromList instead.
  22.         <29>     10/3/95    eeh        1284995: new default param to
  23.                                     SetDialogTextStyle
  24.         <28>     9/12/95    DM        1280020 FB1 part trans dlg mem leaks
  25.         <27>      9/7/95    CG        #1229981 FB2:No Trans dlg when no
  26.                                     translators are installed.
  27.         <26>     8/30/95    EL        1279451: Translation dialog problem if
  28.                                     exception thrown.
  29.         <25>     8/25/95    eeh        1230007: new param to DrawITextInDlogBox
  30.         <24>     8/24/95    CC        1242669,1279966,1279963: Fixes to
  31.                                     ShowTranslationDialog.
  32.         <23>     8/23/95    CC        1242581: ShowTranslateDialog: Copy selected
  33.                                     editor on return if OK button pressed.
  34.         <22>     7/28/95    CC        1258538: Remove declaration of
  35.                                     GetFromAndToKinds.
  36.         <21>     7/26/95    DM        #1270320: Memory leak fixes.
  37.         <20>     6/21/95    CC        1260937: BB: ODTypeListIterator must return
  38.                                     copies of ODType values.
  39.         <19>     6/16/95    CC        1258538: ShowTranslateDialog: Release kind
  40.                                     and editor menu resources; also check
  41.                                     GetMenu result; Added TRY block.
  42.                                     Added GetOrderedCollectionElement.
  43.                                     Removed GetFromAndToKinds.
  44.                                     1259356: ShowPartTranslateDialog:
  45.                                     ChangeKind or externalize before attempting
  46.                                     translation.
  47.                                     1259719: ShowPartTranslateDialog: Use
  48.                                     ChangeKindAndEditor.
  49.                                     Added #includes of OrdColl.h and
  50.                                     StdTypIO.h.
  51.         <18>      6/7/95    jpa        Fixed EndUsingLibRsrcs calls. [1255369]
  52.         <17>      6/7/95    CC        1236299: Moved CUsingLibraryResources call
  53.                                     from ShowPartTranslateDialog to
  54.                                     ShowTranslateDialog.  Wrapped other uses of
  55.                                     resource manager with
  56.                                     BeginUsingLibraryResources and
  57.                                     EndUsingLibraryResources.
  58.         <16>      6/2/95    CC        1236617: Use CreateTypeList factory method.
  59.         <15>     5/26/95    VL        1251403: Multithreading naming support.
  60.         <14>     5/18/95    CG        #1249263 BB: BndNSUtl.cpp does not compile
  61.                                     standalone.
  62.         <13>      5/1/95    CG        #1240845    BB: Kinds popups need to include
  63.                                     all kinds that an editor can edit.
  64.         <12>     4/25/95    CC        1242555: $5 entered as bug 1242666.
  65.                                     1242555: ShowTranslateDialog: $5 entered as
  66.                                     bug 1242669.
  67.         <11>     4/14/95    TÇ        #1235279 BB: InfoUtil & StdTypIO functions
  68.                                     should take Environment* and SU* when
  69.                                     possible
  70.         <10>     3/28/95    CC        1229640: Added forPaste parameter to
  71.                                     ShowTranslateDialog.
  72.                                     DrawEditorName calls DrawITextInDlogBox
  73.                                     utility.
  74.          <9>     3/28/95    CC        1233117: Removed unused ODStorageUnit
  75.                                     parameter from  ShowPartTranslateDialog.
  76.                                     1232850: Fixed bug causing crash.
  77.          <8>     3/27/95    CC        1229640: Split ShowTranslateDialog() into
  78.                                     two methods: ShowPartTranslateDialog() and
  79.                                     ShowPartTranslateDialog().  Many changes to
  80.                                     support display from Paste As dialog.
  81.          <7>      3/6/95    jpa        Use dialog utilities (ODGetNewDialog,
  82.                                     ODDialogFilterProc) to make dlogs movable.
  83.                                     [1218957]
  84.          <6>     1/12/95    jpa        Don't use obsolete Toolbox names [1211211]
  85.          <5>     1/10/95    CG        1197870: If no Part is root and TransDlg is
  86.                                     dismissed, close document.
  87.          <4>    12/23/94    JBS        1186869: hide ODPartWrapper from public
  88.                                     API; 1192557: ODPartWrapper realPart access
  89.          <3>    12/20/94    CG        #1207346: Switching editors was crashing.
  90.          <2>    12/13/94    CG        #1187128: Added StorageUnit and PartWrapper
  91.                                     parameters to ShowTranslateDialog().
  92.          <1>    11/17/94    CG        first checked in
  93.     To Do:
  94.     In Progress:
  95.         
  96. */
  97.  
  98. #ifndef _TRANSDLG_
  99. #include "TransDlg.h"
  100. #endif
  101.  
  102. #ifndef _TRNDLGDF_
  103. #include <TrnDlgDf.h>
  104. #endif
  105.  
  106. #ifndef _USERSRCM_
  107. #include <UseRsrcM.h>
  108. #endif
  109.  
  110. #ifndef __DIALOGS__
  111. #include <Dialogs.h>
  112. #endif
  113.  
  114. #ifndef SOM_ODSession_xh
  115. #include <ODSessn.xh>
  116. #endif
  117.  
  118. #ifndef SOM_ODPart_xh
  119. #include <Part.xh>
  120. #endif
  121.  
  122. #ifndef SOM_ODStorageSystem_xh
  123. #include <ODStor.xh>
  124. #endif
  125.  
  126. #ifndef SOM_ODStorageUnit_xh
  127. #include <StorageU.xh>
  128. #endif
  129.  
  130. #ifndef SOM_ODTypeList_xh
  131. #include <TypeList.xh>
  132. #endif
  133.  
  134. #ifndef SOM_ODTypeListIterator_xh
  135. #include <TypLsItr.xh>
  136. #endif
  137.  
  138. #ifndef _BINDNGH_
  139. #include <BindngH.h>
  140. #endif
  141.  
  142. #ifndef _BNDNSUTL_
  143. #include <BndNSUtl.h>
  144. #endif
  145.  
  146. #ifndef _ODUTILS_
  147. #include <ODUtils.h>
  148. #endif
  149.  
  150. #ifndef _PASCLSTR_
  151. #include <PasclStr.h>
  152. #endif
  153.  
  154. #ifndef _DLOGUTIL_
  155. #include <DlogUtil.h>
  156. #endif
  157.  
  158. #ifndef SOM_ODFrame_xh
  159. #include <Frame.xh>
  160. #endif
  161.  
  162. #ifndef SOM_ODWindowState_xh
  163. #include <WinStat.xh>
  164. #endif
  165.  
  166. #ifndef SOM_Module_OpenDoc_StdProps_defined
  167. #include <StdProps.xh>
  168. #endif
  169.  
  170. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  171. #include <StdTypes.xh>
  172. #endif
  173.  
  174. #ifndef SOM_ODTranslation_xh
  175. #include <Translt.xh>
  176. #endif
  177.  
  178. #ifndef _EDITRSET_
  179. #include <EditrSet.h>
  180. #endif
  181.  
  182. #ifndef SOM_ODPartWrapper_xh
  183. #include <PartWrap.xh>
  184. #endif
  185.  
  186. #include <somcls.xh>
  187. #include <somcm.xh>
  188.  
  189. #ifndef _ODMEMORY_
  190. #include <ODMemory.h>
  191. #endif
  192.  
  193. #ifndef __TEXTUTILS__
  194. #include <TextUtils.h>
  195. #endif
  196.  
  197. #ifndef _INFOUTIL_
  198. #include <InfoUtil.h>
  199. #endif
  200.  
  201. #ifndef _TRANSUTL_
  202. #include <TransUtl.h>
  203. #endif
  204.  
  205. #ifndef _ORDCOLL_
  206. #include "OrdColl.h"
  207. #endif
  208.  
  209. #ifndef _STDTYPIO_
  210. #include "StdTypIO.h"
  211. #endif
  212.  
  213. #ifndef _TEMPOBJ_
  214. #include <TempObj.h>
  215. #endif
  216.  
  217. #ifndef _ISOSTR_
  218. #include <ISOStr.h>
  219. #endif
  220.  
  221. #pragma segment TransDlg
  222.  
  223. //==============================================================================
  224. // Constants
  225. //==============================================================================
  226.  
  227. const Boolean kNoDefaultButton = kODFalse;
  228.  
  229. const short kControlInactive = 255;
  230. const short kControlActive = 0;
  231.  
  232. //==============================================================================
  233. // Scalar Types
  234. //==============================================================================
  235.  
  236. //==============================================================================
  237. // Local Classes
  238. //==============================================================================
  239.  
  240. //==============================================================================
  241. // Global Variables
  242. //==============================================================================
  243.  
  244. // Use a global to pass the editor name to DrawEditorName
  245. ODStatic ODName* gEditorName = kODNULL;
  246.  
  247. //==============================================================================
  248. // Function Prototype
  249. //==============================================================================
  250. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name);
  251.  
  252. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item);
  253.  
  254. ODStatic ODUShort GetOrderedCollectionElement(OrderedCollection* collection, ODUShort index);
  255.  
  256. //==============================================================================
  257. // Local Functions
  258. //==============================================================================
  259.  
  260. //------------------------------------------------------------------------------
  261. // DisposeGlobalODNameAndZeroPtr
  262. //------------------------------------------------------------------------------
  263. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name)
  264. {
  265.     if (*name)
  266.     {
  267.         // simple way to force deletion of old name value without knowing
  268.         // that DisposeIText is the right way to destroy an ODName:
  269.         TempODName tempName = *name;
  270.         *name = kODNULL;
  271.     }
  272. }
  273.  
  274. //------------------------------------------------------------------------------
  275. // DrawEditorName
  276. //------------------------------------------------------------------------------
  277.  
  278. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item)
  279. {
  280.     short            itemType;
  281.     Handle            itemHandle;
  282.     Rect            itemRect;
  283.  
  284.     GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  285.  
  286.     if ( gEditorName )
  287.         DrawITextInDlogBox(gEditorName, &itemRect, dialog, kODTrue);
  288. }
  289.  
  290. //------------------------------------------------------------------------------
  291. // GetOrderedCollectionElement
  292. //------------------------------------------------------------------------------
  293.  
  294. ODStatic ODUShort GetOrderedCollectionElement(OrderedCollection* collection, ODUShort index)
  295. {
  296.     OrderedCollectionIterator* oci = collection->CreateIterator();
  297.  
  298.     ODUShort elem = 0;
  299.  
  300.     for (    elem = (ODUShort) oci->First();
  301.             oci->IsNotComplete(); 
  302.             elem = (ODUShort) oci->Next() )
  303.     {
  304.         if ( --index == 0 )
  305.             break;
  306.     }
  307.  
  308.     ODDeleteObject(oci);
  309.  
  310.     return elem;
  311. }
  312.  
  313. //------------------------------------------------------------------------------
  314. // InitialEditorSetup
  315. //------------------------------------------------------------------------------
  316. // On entry, kindIndex identifies the preferred kind in kindList.
  317. // Returns in kindIndex the index into kindList of a type for which editors are
  318. // available.  If none are available, kindIndex is unchanged, and the returned
  319. // editor set is empty.
  320. ODStatic EditorSet* InitialEditorSetup(
  321.                         ODTypeList*        kindList,
  322.                         ODUShort*        kindIndex,
  323.                         MenuHandle        editorMenu, 
  324.                         ControlHandle    popupCtlHndl, 
  325.                         ODSession*        session)
  326. {
  327.     // Create an empty editor list
  328.     EditorSet* editorList = new EditorSet;
  329.     editorList->InitEditorSet();
  330.  
  331.     Environment* ev = somGetGlobalEnvironment();
  332.  
  333.     ODUShort kindItems = kindList->Count(ev);
  334.  
  335.     if ( (*kindIndex > 0) && (*kindIndex <= kindItems) )
  336.     {
  337.          TempODType initialKind = GetTypeListItem(kindList, *kindIndex);
  338.          if ( initialKind )
  339.             SetupEditorMenu(initialKind, editorList, editorMenu, popupCtlHndl, session);
  340.      }
  341.  
  342.     // If the initial kind is supported by at least one editor, 
  343.     // or there is no other kind, return
  344.     if ( (editorList->GetEditorCount() > 0) || (kindItems < 2) )
  345.         return editorList;
  346.  
  347.     ODUShort index = 1;
  348.     ODTypeListIterator* iter = kindList->CreateTypeListIterator(ev);
  349.  
  350.     TempODType kind = kODNULL;
  351.     for (kind = iter->First(ev);
  352.          iter->IsNotComplete(ev);
  353.          kind = iter->Next(ev))
  354.     {
  355.         if ( SetupEditorMenu(kind, editorList, editorMenu, popupCtlHndl, session) )
  356.         {
  357.             *kindIndex = index;
  358.             break;
  359.         }
  360.         ODDisposePtr(kind);
  361.         kind = kODNULL;
  362.         ++index;
  363.     }
  364.     delete iter;
  365.  
  366.     return editorList;
  367. }    
  368.  
  369. //------------------------------------------------------------------------------
  370. // IndexOfSupportedKind
  371. //------------------------------------------------------------------------------
  372. // On entry, kindIndex identifies the preferred kind in kindList.
  373. // Returns in kindIndex the index into kindList of a type for which editors are
  374. // available.  If no editor is available for any kind, kindIndex is unchanged
  375. // and false is returned.
  376. ODStatic ODBoolean IndexOfSupportedKind(
  377.                         ODTypeList*            kindList,
  378.                         ODUShort*            kindIndex,
  379.                         ODEditor            editorID,
  380.                         ODNameSpaceManager*    nsm)
  381. {
  382.     Environment* ev = somGetGlobalEnvironment();
  383.  
  384.     ODUShort kindItems = kindList->Count(ev);
  385.  
  386.     if ( (*kindIndex > 1) && (*kindIndex <= kindItems) )
  387.     {
  388.          TempODType initialKind = GetTypeListItem(kindList, *kindIndex);
  389.          if ( EditorSupportsKind(nsm, editorID, initialKind) )
  390.              return kODTrue;
  391.      }
  392.  
  393.     ODBoolean result = kODFalse;
  394.     ODUShort index = 1;
  395.     ODTypeListIterator* iter = kindList->CreateTypeListIterator(ev);
  396.  
  397.     TempODType kind = kODNULL;
  398.     for (kind = iter->First(ev);
  399.          iter->IsNotComplete(ev);
  400.          kind = iter->Next(ev))
  401.     {
  402.          if ( EditorSupportsKind(nsm, editorID, kind) )
  403.         {
  404.             *kindIndex = index;
  405.             result = kODTrue;
  406.             break;
  407.         }
  408.         ODDisposePtr(kind);
  409.         kind = kODNULL;
  410.         ++index;
  411.     }
  412.     delete iter;
  413.  
  414.     return result;
  415. }    
  416.  
  417. //==============================================================================
  418. // Class TranslationDialog
  419. //==============================================================================
  420.  
  421. //------------------------------------------------------------------------------
  422. // TranslationDialog::TranslationDialog
  423. //------------------------------------------------------------------------------
  424. TranslationDialog::TranslationDialog()
  425. {
  426.     fSession = kODNULL;
  427. }
  428.  
  429. //------------------------------------------------------------------------------
  430. // TranslationDialog::~TranslationDialog
  431. //------------------------------------------------------------------------------
  432. TranslationDialog::~TranslationDialog()
  433. {
  434. }
  435.  
  436. //------------------------------------------------------------------------------
  437. // TranslationDialog::InitTranslationDialog
  438. //------------------------------------------------------------------------------
  439. void TranslationDialog::InitTranslationDialog(ODSession* session)
  440. {
  441.     fSession = session;
  442. }
  443.  
  444. //------------------------------------------------------------------------------
  445. // TranslationDialog::ShowPartTranslateDialog
  446. //------------------------------------------------------------------------------
  447. ODBoolean  TranslationDialog::ShowPartTranslateDialog(ODPartWrapper* partWrapper)
  448. {
  449.     Environment *ev = somGetGlobalEnvironment();
  450.     ODTypeList*    kindList = kODNULL;
  451.     ODTypeList*    translateToList = kODNULL;
  452.     OrderedCollection* translateFromList = kODNULL;
  453.     
  454.     ODVolatile(kindList);
  455.     ODVolatile(translateToList);
  456.     ODVolatile(translateFromList);
  457.  
  458.     ODBoolean translationSuccessful = kODFalse;
  459.  
  460.     TRY
  461.         ODBinding* binding = fSession->GetBinding(ev);
  462.         ODNameSpaceManager* nsm = fSession->GetNameSpaceManager(ev);
  463.         ODStorageUnit* storageUnit = partWrapper->GetStorageUnit(ev);
  464.         
  465.         // Create the list of kinds and translations
  466.         kindList = fSession->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  467.         
  468.         ContentValueTypes(storageUnit, kindList);
  469.  
  470.         { TempODEditor tempEditor = GetCurrentEditorForPart(partWrapper);
  471.           GetAllKindsForEditor(nsm, kindList, tempEditor);
  472.         }
  473.  
  474.         translateToList = fSession->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  475.         
  476.         translateFromList = new OrderedCollection;
  477.         
  478.         GetDestinationKindsList(kindList, translateToList, translateFromList, fSession);
  479.         
  480.         if (translateToList->Count(ev) == 0)
  481.         {
  482.             TempODName         partName    = ODGetPOName(ev, partWrapper,0);
  483.             Str255     partNameString = "\p";
  484.             GetITextPString( partName, partNameString );
  485.  
  486.             ParamText(partNameString, "\p", "\p", "\p");
  487.     
  488.             fSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  489.             ShowAlert(ev, kODNoTransAlert, GetODButtonKeyFilterProc(), fSession);
  490.             fSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  491.         }
  492.         else
  493.         {
  494.             fSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  495.         
  496.             ODUShort selectedKind = 0;
  497.             ODEditor editorID = kODNULL;
  498.             ODBoolean result = this->ShowTranslateDialog(translateToList, 
  499.                                                             &selectedKind, 
  500.                                                             &editorID,
  501.                                                             kODTrue,
  502.                                                             kODFalse);
  503.         
  504.             TempODEditor tempEditorID = editorID; // make sure it is deleted eventually
  505.             
  506.             fSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  507.         
  508.             if ( result )
  509.             {
  510.                 TempODType toKind = GetTypeListItem(translateToList, selectedKind);
  511.                 TempODType fromKind = GetTypeListItem(kindList, GetOrderedCollectionElement(translateFromList, selectedKind));
  512.     
  513.                 if ( fromKind && toKind )
  514.                 {
  515.                     // If fromKind does not yet exist, force part to change to that kind.
  516.                     // Otherwise, force the part to externalize any changes to its storage unit.
  517.                     if ( !storageUnit->Exists(ev, kODPropContents, fromKind, 0) )
  518.                         partWrapper->ChangeKind(ev, fromKind);
  519.                     else
  520.                         partWrapper->Externalize(ev);
  521.     
  522.                     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fromKind, 0, kODPosUndefined);
  523.                     TempODStorageUnitView fromView = storageUnit->CreateView(ev);
  524.                     
  525.                     storageUnit->Focus(ev, kODPropContents, kODPosAll, kODTypeAll, 0, kODPosUndefined);
  526.     
  527.                     storageUnit->AddValue( ev, toKind );
  528.                     TempODStorageUnitView toView = storageUnit->CreateView(ev);
  529.                     
  530.                     ODTranslation* translation = fSession->GetTranslation(ev);
  531.             
  532.                     translation->TranslateView(ev, fromView, toView);
  533.                     
  534.                     ChangeKindAndEditor(ev, partWrapper, toKind, editorID, nsm);
  535.     
  536.                     translationSuccessful = kODTrue;
  537.                 }
  538.             }
  539.         }
  540.     
  541.     CATCH_ALL
  542.         WARN("ShowPartTranslateDialog caught exception %d\n", ErrorCode());
  543.         ODDeleteObject(kindList);
  544.         ODDeleteObject(translateToList);
  545.         ODDeleteObject(translateFromList);
  546.         RERAISE;
  547.     ENDTRY
  548.  
  549.     delete kindList;
  550.     delete translateToList;
  551.     delete translateFromList;
  552.  
  553.     return translationSuccessful;
  554. }
  555.  
  556. //------------------------------------------------------------------------------
  557. // TranslationDialog::ShowTranslateDialog
  558. //------------------------------------------------------------------------------
  559. ODBoolean  TranslationDialog::ShowTranslateDialog(
  560.                 ODTypeList*    translateToList,
  561.                 ODUShort*    selectedKind,
  562.                 ODEditor*    editor,
  563.                 ODBoolean    canChangeEditor,
  564.                 ODBoolean    forPaste)
  565. {
  566.     short              itemHit = kODTransCancelBtn;
  567.     short            itemType;
  568.     Handle            itemHandle;
  569.     ControlHandle    kindPopupControlHandle;
  570.     ControlHandle    editorPopupControlHandle;
  571.     Rect            itemRect;
  572.     Rect            editorPopupRect;
  573.     ODBoolean        translationSuccessful = kODFalse;
  574.     Environment     *ev = somGetGlobalEnvironment();
  575.     ODUShort        selectedEditor = 0;
  576.     ODSLong            refSaved;
  577.     OSErr            resErr;
  578.     ODUShort        kindIndex = ( *selectedKind > 0 ? *selectedKind : 1);
  579.  
  580.     DialogPtr          dlg;                        ODVolatile(dlg);
  581.     WindowPtr        savePort;                    ODVolatile(savePort);
  582.     UserItemUPP        DrawEditorNameUPP = kODNULL;ODVolatile(DrawEditorNameUPP);
  583.     EditorSet*        editorList = kODNULL;        ODVolatile(editorList);
  584.     MenuHandle        kindMenu = kODNULL;            ODVolatile(kindMenu);
  585.     MenuHandle        editorMenu = kODNULL;        ODVolatile(editorMenu);
  586.     
  587.     {
  588.         CUsingLibraryResources r;
  589.         dlg  = ODGetNewDialog(ev, (forPaste ? kODTransDlgID : kODPartTransDlgID), fSession, kNoDefaultButton);
  590.     }
  591.  
  592.     if (dlg)
  593.     {
  594.         GetPort(&savePort);
  595.         TRY
  596.             SetPort(dlg);
  597.     
  598.             { CUsingLibraryResources r;
  599.                 SetDialogTextStyle(dlg, (forPaste ? kODTransDlgID : kODPartTransDlgID),
  600.                         smCurrentScript);
  601.             }
  602.     
  603.             // Initialize control handles
  604.             GetDialogItem(dlg, kODTransKindPopup, &itemType, (Handle*) &kindPopupControlHandle, &itemRect);
  605.             GetDialogItem(dlg, kODTransEditorPopup, &itemType, (Handle*) &editorPopupControlHandle, &editorPopupRect);
  606.     
  607.             // Set the draw routine for the default button outline item
  608.             GetDialogItem(dlg, kODTransDefaultButtonOutline, &itemType, &itemHandle, &itemRect);
  609.             SetDialogItem(dlg, kODTransDefaultButtonOutline, itemType, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  610.     
  611.             // Set up Kind Menu
  612.             refSaved = BeginUsingLibraryResources();
  613.             kindMenu = GetMenu(kODTransKindMenu);
  614.             resErr = ResError();
  615.             EndUsingLibraryResources(refSaved);
  616.             THROW_IF_NULL(kindMenu, resErr ? resErr : resNotFound);
  617.     
  618.             if (translateToList->Count(ev) == 0 )
  619.             {
  620.                 AppendMenu(kindMenu, "\p");
  621.                 HiliteControl(kindPopupControlHandle, kControlInactive);
  622.             }
  623.             else
  624.             {
  625.                 AddTypesToMenu(translateToList, kindMenu, kODNULL, kODNULL, fSession);
  626.                 if ( !canChangeEditor )
  627.                     EnableTypesInMenu(translateToList, kindMenu, *editor, fSession->GetNameSpaceManager(ev));
  628.             }
  629.             SetControlMinimum(kindPopupControlHandle, 1);
  630.             SetControlMaximum(kindPopupControlHandle, CountMItems(kindMenu));
  631.     
  632.             // Set up Editor Menu
  633.             refSaved = BeginUsingLibraryResources();
  634.             editorMenu = GetMenu(kODTransEditorMenu);
  635.             resErr = ResError();
  636.             EndUsingLibraryResources(refSaved);
  637.             THROW_IF_NULL(editorMenu, resErr ? resErr : resNotFound);
  638.     
  639.             // If an editor was specified, display that editor as static text in place
  640.             // of the popup, and disable translation kinds not supported by the editor
  641.             if ( canChangeEditor )
  642.             {
  643.                 // Pick a supported kind and create the editor list
  644.                 editorList = InitialEditorSetup(
  645.                                     translateToList,
  646.                                     &kindIndex,
  647.                                     editorMenu, 
  648.                                     editorPopupControlHandle, 
  649.                                     fSession);
  650.  
  651.                 ODBoolean anyEditor = (editorList->GetEditorCount() > 0);
  652.                 EnableOkButton(dlg, anyEditor);
  653.  
  654.                 if ( anyEditor )
  655.                 {
  656.                     if ( *editor != kODNULL )
  657.                         selectedEditor = IndexOfEditorInList(editorList, *editor);
  658.                     if ( selectedEditor == 0 )
  659.                         selectedEditor = 1;
  660.         
  661.                     SetControlValue(editorPopupControlHandle, selectedEditor);
  662.                         
  663.                     HideDialogItem(dlg, kODTransEditorLabel);
  664.                     HideDialogItem(dlg, kODTransEditorText);
  665.                     HideDialogItem(dlg, kODTransNoEditorText);
  666.                 }
  667.                 else
  668.                 {
  669.                     HideDialogItem(dlg, kODTransEditorPopup);
  670.                     HideDialogItem(dlg, kODTransEditorText);
  671.                 }
  672.             }
  673.             else
  674.             {
  675.                 // Pick a supported kind
  676.                 ODBoolean anyKindSupported = IndexOfSupportedKind(
  677.                                     translateToList, 
  678.                                     &kindIndex, 
  679.                                     *editor, 
  680.                                     fSession->GetNameSpaceManager(ev));
  681.                 
  682.                 EnableOkButton(dlg, anyKindSupported);
  683.  
  684.                 // Set text of static editor item
  685.                 DisposeGlobalODNameAndZeroPtr(&gEditorName);
  686.                 if ( GetUserEditorFromEditor(fSession->GetNameSpaceManager(ev), *editor, &gEditorName) )
  687.                 {
  688.                     GetDialogItem(dlg, kODTransEditorText, &itemType, &itemHandle, &itemRect);
  689.                     DrawEditorNameUPP = NewUserItemProc(DrawEditorName);
  690.                     SetDialogItem(dlg, kODTransEditorText, userItem+itemDisable, (Handle) DrawEditorNameUPP, &itemRect);
  691.                 }
  692.     
  693.                 HideDialogItem(dlg, kODTransEditorPopup);
  694.                 HideDialogItem(dlg, kODTransNoEditorText);
  695.             }
  696.     
  697.             SetControlValue(kindPopupControlHandle, kindIndex);
  698.  
  699.             ShowWindow(dlg);
  700.  
  701.             do {
  702.                 refSaved = BeginUsingLibraryResources();
  703.                 ModalDialog(GetODButtonKeyFilterProc(), &itemHit);
  704.                 EndUsingLibraryResources(refSaved);
  705.     
  706.                 switch (itemHit)
  707.                 {
  708.                     case kODTransKindPopup:
  709.                         ODSShort kindItem = (ODUShort) GetControlValue(kindPopupControlHandle);
  710.                         if (kindItem != kindIndex)
  711.                         {
  712.                             if ( canChangeEditor )
  713.                             {
  714.                                 TempODEditor selectedEditorID = GetThisEditorFromList(selectedEditor, editorList);
  715.  
  716.                                 editorList->RemoveAllEditors();
  717.                                 TempODType toKind = GetTypeListItem(translateToList, kindItem);
  718.                                 ODBoolean anyEditors = SetupEditorMenu(
  719.                                                             toKind,
  720.                                                             editorList, 
  721.                                                             editorMenu, 
  722.                                                             editorPopupControlHandle, 
  723.                                                             fSession);
  724.                                 EnableOkButton(dlg, anyEditors);
  725.                                 
  726.                                 ODUShort newEditor = (ODUShort) GetControlValue(editorPopupControlHandle);
  727.                                 ODSShort selectedEditor = IndexOfEditorInList(editorList, selectedEditorID);
  728.  
  729.                                 if ( (selectedEditor != 0 ) && (newEditor != selectedEditor) )
  730.                                 {
  731.                                     CUsingLibraryResources r;
  732.                                     SetControlValue(editorPopupControlHandle, selectedEditor);
  733.                                 }
  734.                                 else
  735.                                 {
  736.                                     selectedEditor = newEditor;
  737.                                     SetPort(dlg);
  738.                                     InvalRect(&editorPopupRect);    // Redraw the popup
  739.                                 }
  740.                             }
  741.                             kindIndex = kindItem;
  742.                         }
  743.                         break;
  744.     
  745.                     case kODTransEditorPopup:
  746.                         selectedEditor = (ODUShort) GetControlValue(editorPopupControlHandle);
  747.                         break;
  748.     
  749.                     default:
  750.                         break;
  751.                 }
  752.             } while ( (itemHit != kODTransOKBtn) && (itemHit != kODTransCancelBtn) );
  753.     
  754.             if ( itemHit == kODTransOKBtn ) 
  755.             {
  756.                 *selectedKind = kindIndex;
  757.                 if ( canChangeEditor )
  758.                 {
  759.                     ODEditor newEditor = GetThisEditorFromList(selectedEditor, editorList);
  760.                     if ( newEditor )
  761.                     {
  762.                         ODDisposePtr((ODPtr) *editor);
  763.                         *editor = newEditor;
  764.                     }
  765.                 }
  766.             }
  767.     
  768.         CATCH_ALL
  769.             ODDeleteObject(editorList);
  770.         
  771.             ODDisposeRoutineDescriptor(DrawEditorNameUPP);
  772.     
  773.             refSaved = BeginUsingLibraryResources();
  774.             if ( kindMenu )
  775.             {
  776.                 DeleteMenu(kODTransKindMenu);
  777.                 ReleaseResource((Handle) kindMenu);
  778.             }
  779.             if ( editorMenu )
  780.             {
  781.                 DeleteMenu(kODTransEditorMenu);
  782.                 ReleaseResource((Handle) editorMenu);
  783.             }
  784.             DisposeDialog(dlg);
  785.             EndUsingLibraryResources(refSaved);
  786.  
  787.             DisposeGlobalODNameAndZeroPtr(&gEditorName);
  788.  
  789.             SetPort(savePort);
  790.             RERAISE;
  791.         ENDTRY
  792.  
  793.         ODDeleteObject(editorList);
  794.     
  795.         ODDisposeRoutineDescriptor(DrawEditorNameUPP);
  796.  
  797.         refSaved = BeginUsingLibraryResources();
  798.         if ( kindMenu )
  799.         {
  800.             DeleteMenu(kODTransKindMenu);
  801.             ReleaseResource((Handle) kindMenu);
  802.         }
  803.         if ( editorMenu )
  804.         {
  805.             DeleteMenu(kODTransEditorMenu);
  806.             ReleaseResource((Handle) editorMenu);
  807.         }
  808.         DisposeDialog(dlg);
  809.         EndUsingLibraryResources(refSaved);
  810.     
  811.         DisposeGlobalODNameAndZeroPtr(&gEditorName);
  812.  
  813.         SetPort(savePort);
  814.     }
  815.  
  816.     return (itemHit == kODTransOKBtn);
  817. }
  818.